package com.example.eurekaclient;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@org.springframework.web.bind.annotation.RestController
public class RestController {
    @Autowired
    private DiscoveryClient discoveryClient;

    @RequestMapping("test")
    String test() {
        List<ServiceInstance> instances = discoveryClient.getInstances("eureka-client");
        if (instances != null) {
            for (ServiceInstance instance : instances) {
                return instance.getHost() + ":" + instance.getServiceId();
            }
        }
        return "test-client";
    }

}
